home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.metal;
-
- import com.sun.java.swing.AbstractButton;
- import com.sun.java.swing.Action;
- import com.sun.java.swing.BorderFactory;
- import com.sun.java.swing.Box;
- import com.sun.java.swing.BoxLayout;
- import com.sun.java.swing.JButton;
- import com.sun.java.swing.JComboBox;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JLabel;
- import com.sun.java.swing.JList;
- import com.sun.java.swing.JPanel;
- import com.sun.java.swing.JScrollPane;
- import com.sun.java.swing.JTextField;
- import com.sun.java.swing.JToggleButton;
- import com.sun.java.swing.event.ListSelectionEvent;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.basic.BasicFileChooserUI;
- import com.sun.java.swing.preview.JFileChooser;
- import java.awt.BorderLayout;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Insets;
- import java.beans.PropertyChangeEvent;
- import java.io.File;
-
- public class MetalFileChooserUI extends BasicFileChooserUI {
- private JPanel centerPanel;
- private JComboBox directoryComboBox;
- private DirectoryComboBoxModel directoryComboBoxModel;
- private Action directoryComboBoxAction = new DirectoryComboBoxAction(this);
- private FilterComboBoxModel filterComboBoxModel;
- private JTextField filenameTextField;
- private JList list;
- private JButton approveButton;
- private JButton cancelButton;
- private JComboBox filterComboBox;
- private JPanel bodyPanel = null;
- private static final Dimension hstrut10 = new Dimension(10, 1);
- private static final Dimension hstrut25 = new Dimension(25, 1);
- private static final Dimension vstrut10 = new Dimension(1, 10);
- private static final Insets shrinkwrap = new Insets(0, 0, 0, 0);
- private static int PREF_WIDTH = 500;
- private static int PREF_HEIGHT = 300;
- private static Dimension PREF_SIZE;
- private static int MIN_WIDTH;
- private static int MIN_HEIGHT;
- private static Dimension MIN_SIZE;
- private static int LIST_MIN_WIDTH;
- private static int LIST_MIN_HEIGHT;
- private static Dimension LIST_MIN_SIZE;
-
- static {
- PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT);
- MIN_WIDTH = 400;
- MIN_HEIGHT = 200;
- MIN_SIZE = new Dimension(MIN_WIDTH, MIN_HEIGHT);
- LIST_MIN_WIDTH = 400;
- LIST_MIN_HEIGHT = 100;
- LIST_MIN_SIZE = new Dimension(LIST_MIN_WIDTH, LIST_MIN_HEIGHT);
- }
-
- public MetalFileChooserUI(JFileChooser filechooser) {
- super(filechooser);
- }
-
- protected DirectoryComboBoxModel createDirectoryComboBoxModel() {
- return new DirectoryComboBoxModel(this);
- }
-
- protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer() {
- return new DirectoryComboBoxRenderer(this);
- }
-
- protected FilterComboBoxModel createFilterComboBoxModel() {
- return new FilterComboBoxModel(this);
- }
-
- protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
- return new FilterComboBoxRenderer(this);
- }
-
- protected JPanel createList() {
- JPanel p = new JPanel(new BorderLayout());
- this.list = new JList();
- this.list.setCellRenderer(new FileRenderer(this));
- this.list.setModel(super.model);
- this.list.addListSelectionListener(((BasicFileChooserUI)this).createListSelectionListener());
- this.list.addMouseListener(((BasicFileChooserUI)this).createDoubleClickListener(this.list));
- JScrollPane scrollpane = new JScrollPane(this.list);
- ((JComponent)scrollpane).setBorder(BorderFactory.createLoweredBevelBorder());
- ((Container)p).add(scrollpane, "Center");
- return p;
- }
-
- public static ComponentUI createUI(JComponent c) {
- return new MetalFileChooserUI((JFileChooser)c);
- }
-
- public void ensureFileIsVisible(File f) {
- if (super.model.contains(f)) {
- this.list.setSelectedIndex(super.model.indexOf(f));
- this.list.ensureIndexIsVisible(this.list.getSelectedIndex());
- }
-
- }
-
- public String getDirectoryName() {
- return null;
- }
-
- public String getFileName() {
- return this.filenameTextField != null ? this.filenameTextField.getText() : null;
- }
-
- public Dimension getMaximumSize(JComponent x) {
- return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
- }
-
- public Dimension getMinimumSize(JComponent x) {
- return MIN_SIZE;
- }
-
- public Dimension getPreferredSize(JComponent x) {
- return PREF_SIZE;
- }
-
- public void installComponents() {
- ((BasicFileChooserUI)this).getFileChooser().setLayout(new BoxLayout(((BasicFileChooserUI)this).getFileChooser(), 1));
- ((BasicFileChooserUI)this).getFileChooser().add(Box.createRigidArea(vstrut10));
- JPanel topPanel = new JPanel();
- ((Container)topPanel).setLayout(new BoxLayout(topPanel, 0));
- ((BasicFileChooserUI)this).getFileChooser().add(topPanel);
- ((BasicFileChooserUI)this).getFileChooser().add(Box.createRigidArea(vstrut10));
- JLabel l = new JLabel("Look in:");
- ((JComponent)l).setAlignmentX(0.0F);
- ((JComponent)l).setAlignmentY(0.5F);
- ((Container)topPanel).add(Box.createRigidArea(hstrut10));
- ((Container)topPanel).add(l);
- ((Container)topPanel).add(Box.createRigidArea(hstrut25));
- this.directoryComboBox = new JComboBox();
- this.directoryComboBoxModel = this.createDirectoryComboBoxModel();
- this.directoryComboBox.setModel(this.directoryComboBoxModel);
- this.directoryComboBox.addActionListener(this.directoryComboBoxAction);
- this.directoryComboBox.setRenderer(this.createDirectoryComboBoxRenderer());
- this.directoryComboBox.setAlignmentX(0.0F);
- this.directoryComboBox.setAlignmentY(0.5F);
- ((Container)topPanel).add(this.directoryComboBox);
- ((Container)topPanel).add(Box.createRigidArea(hstrut10));
- JButton b = new JButton(super.upFolderIcon);
- ((JComponent)b).setToolTipText("Up One Level");
- ((JComponent)b).setAlignmentX(0.0F);
- ((JComponent)b).setAlignmentY(0.5F);
- ((AbstractButton)b).setMargin(shrinkwrap);
- ((AbstractButton)b).setFocusPainted(false);
- ((AbstractButton)b).addActionListener(((BasicFileChooserUI)this).getChangeToParentDirectoryAction());
- ((Container)topPanel).add(b);
- ((Container)topPanel).add(Box.createRigidArea(hstrut10));
- b = new JButton(super.homeFolderIcon);
- ((JComponent)b).setToolTipText("Home");
- ((JComponent)b).setAlignmentX(0.0F);
- ((JComponent)b).setAlignmentY(0.5F);
- ((AbstractButton)b).setMargin(shrinkwrap);
- ((AbstractButton)b).setFocusPainted(false);
- ((AbstractButton)b).addActionListener(((BasicFileChooserUI)this).getGoHomeAction());
- ((Container)topPanel).add(b);
- ((Container)topPanel).add(Box.createRigidArea(hstrut10));
- b = new JButton(super.newFolderIcon);
- ((JComponent)b).setToolTipText("Create New Folder");
- ((JComponent)b).setAlignmentX(0.0F);
- ((JComponent)b).setAlignmentY(0.5F);
- ((AbstractButton)b).setMargin(shrinkwrap);
- ((AbstractButton)b).setFocusPainted(false);
- ((AbstractButton)b).addActionListener(((BasicFileChooserUI)this).getNewFolderAction());
- ((Container)topPanel).add(b);
- ((Container)topPanel).add(Box.createRigidArea(hstrut10));
- JToggleButton tb = new JToggleButton(super.listViewIcon);
- ((JComponent)tb).setToolTipText("List");
- ((AbstractButton)tb).setEnabled(false);
- ((AbstractButton)tb).setFocusPainted(false);
- ((JComponent)tb).setAlignmentX(0.0F);
- ((JComponent)tb).setAlignmentY(0.5F);
- ((AbstractButton)tb).setMargin(shrinkwrap);
- ((Container)topPanel).add(tb);
- tb = new JToggleButton(super.detailsViewIcon);
- ((JComponent)tb).setToolTipText("Details");
- ((AbstractButton)tb).setFocusPainted(false);
- ((AbstractButton)tb).setSelected(true);
- ((AbstractButton)tb).setEnabled(false);
- ((JComponent)tb).setAlignmentX(0.0F);
- ((JComponent)tb).setAlignmentY(0.5F);
- ((AbstractButton)tb).setMargin(shrinkwrap);
- ((Container)topPanel).add(tb);
- ((Container)topPanel).add(Box.createRigidArea(hstrut10));
- this.centerPanel = new JPanel(new BorderLayout());
- JPanel p = this.createList();
- ((JComponent)p).setMinimumSize(LIST_MIN_SIZE);
- this.centerPanel.add(p, "Center");
- this.centerPanel.add(((BasicFileChooserUI)this).getAccessoryPanel(), "East");
- JComponent accessory = ((BasicFileChooserUI)this).getFileChooser().getAccessory();
- if (accessory != null) {
- ((BasicFileChooserUI)this).getAccessoryPanel().add(accessory);
- }
-
- ((BasicFileChooserUI)this).getFileChooser().add(this.centerPanel);
- JPanel bottomPanel = new JPanel();
- ((Container)bottomPanel).setLayout(new BoxLayout(bottomPanel, 0));
- ((Container)bottomPanel).add(Box.createRigidArea(hstrut10));
- ((BasicFileChooserUI)this).getFileChooser().add(Box.createRigidArea(vstrut10));
- ((BasicFileChooserUI)this).getFileChooser().add(bottomPanel);
- ((BasicFileChooserUI)this).getFileChooser().add(Box.createRigidArea(vstrut10));
- JPanel labelPanel = new JPanel();
- ((Container)labelPanel).setLayout(new BoxLayout(labelPanel, 1));
- l = new JLabel("File name:");
- ((Container)labelPanel).add(l);
- ((Container)labelPanel).add(Box.createRigidArea(vstrut10));
- l = new JLabel("Files of type:");
- ((Container)labelPanel).add(l);
- ((Container)bottomPanel).add(labelPanel);
- ((Container)bottomPanel).add(Box.createRigidArea(hstrut25));
- JPanel fileAndFilterPanel = new JPanel();
- ((Container)fileAndFilterPanel).setLayout(new BoxLayout(fileAndFilterPanel, 1));
- this.filenameTextField = new JTextField();
- this.filenameTextField.addActionListener(((BasicFileChooserUI)this).getApproveSelectionAction());
- File f = ((BasicFileChooserUI)this).getFileChooser().getSelectedFile();
- if (f != null) {
- this.setFileName(((BasicFileChooserUI)this).getFileChooser().getName(f));
- }
-
- ((Container)fileAndFilterPanel).add(this.filenameTextField);
- ((Container)fileAndFilterPanel).add(Box.createRigidArea(vstrut10));
- this.filterComboBoxModel = this.createFilterComboBoxModel();
- ((BasicFileChooserUI)this).getFileChooser().addPropertyChangeListener(this.filterComboBoxModel);
- this.filterComboBox = new JComboBox(this.filterComboBoxModel);
- this.filterComboBox.setRenderer(this.createFilterComboBoxRenderer());
- ((Container)fileAndFilterPanel).add(this.filterComboBox);
- ((Container)bottomPanel).add(fileAndFilterPanel);
- ((Container)bottomPanel).add(Box.createRigidArea(hstrut10));
- JPanel buttonPanel = new JPanel();
- ((Container)buttonPanel).setLayout(new BoxLayout(buttonPanel, 1));
- this.approveButton = new 1(((BasicFileChooserUI)this).getApproveButtonText());
- this.approveButton.addActionListener(((BasicFileChooserUI)this).getApproveSelectionAction());
- this.approveButton.setToolTipText(((BasicFileChooserUI)this).getApproveButtonToolTipText());
- ((Container)buttonPanel).add(this.approveButton);
- ((Container)buttonPanel).add(Box.createRigidArea(vstrut10));
- this.cancelButton = new 2(super.cancelButtonText);
- this.cancelButton.setToolTipText(BasicFileChooserUI.cancelButtonToolTipText);
- this.cancelButton.addActionListener(((BasicFileChooserUI)this).getCancelSelectionAction());
- ((Container)buttonPanel).add(this.cancelButton);
- ((Container)bottomPanel).add(buttonPanel);
- ((Container)bottomPanel).add(Box.createRigidArea(hstrut10));
- }
-
- public void installUI(JComponent c) {
- super.installUI(c);
- }
-
- public void propertyChange(PropertyChangeEvent e) {
- String prop = e.getPropertyName();
- if (prop.equals("ApproveSelection")) {
- File f = (File)e.getNewValue();
- if (f != null) {
- this.setFileName(((BasicFileChooserUI)this).getFileChooser().getName(f));
- if (super.model.contains(f)) {
- this.list.setSelectedIndex(super.model.indexOf(e.getNewValue()));
- this.list.ensureIndexIsVisible(this.list.getSelectedIndex());
- }
- }
- } else if (prop.equals("directoryChanged")) {
- super.fileView.clearIconCache();
- this.list.clearSelection();
- File currentDirectory = ((BasicFileChooserUI)this).getFileChooser().getCurrentDirectory();
- if (currentDirectory != null) {
- this.directoryComboBoxModel.addItem(currentDirectory);
- ((BasicFileChooserUI)this).getNewFolderAction().setEnabled(currentDirectory.canWrite());
- }
- } else if (prop.equals("fileSelectionChanged")) {
- super.fileView.clearIconCache();
- this.list.clearSelection();
- } else if (prop == "AccessoryChangedProperty") {
- if (super.accessoryPanel != null) {
- if (e.getOldValue() != null) {
- ((BasicFileChooserUI)this).getAccessoryPanel().remove((JComponent)e.getOldValue());
- }
-
- JComponent accessory = (JComponent)e.getNewValue();
- if (accessory != null) {
- ((BasicFileChooserUI)this).getAccessoryPanel().add(accessory, "Center");
- }
- }
- } else if (prop == "ApproveButtonTextChangedProperty" || prop == "DialogTypeChangedProperty") {
- this.approveButton.setText(((BasicFileChooserUI)this).getApproveButtonText());
- this.approveButton.setToolTipText(((BasicFileChooserUI)this).getApproveButtonToolTipText());
- }
-
- }
-
- public void rescanCurrentDirectory() {
- super.model.invalidateFileCache();
- super.model.validateFileCache();
- }
-
- public void setDirectoryName(String dirname) {
- }
-
- public void setFileName(String filename) {
- if (this.filenameTextField != null) {
- this.filenameTextField.setText(filename);
- }
-
- }
-
- public void uninstallUI(JComponent c) {
- ((BasicFileChooserUI)this).getFileChooser().removePropertyChangeListener(this.filterComboBoxModel);
- this.cancelButton.removeActionListener(((BasicFileChooserUI)this).getCancelSelectionAction());
- this.approveButton.removeActionListener(((BasicFileChooserUI)this).getApproveSelectionAction());
- this.filenameTextField.removeActionListener(((BasicFileChooserUI)this).getApproveSelectionAction());
- super.uninstallUI(c);
- }
-
- public void valueChanged(ListSelectionEvent e) {
- File f = ((BasicFileChooserUI)this).getFileChooser().getSelectedFile();
- if (!e.getValueIsAdjusting() && f != null && !((BasicFileChooserUI)this).getFileChooser().isTraversable(f)) {
- this.setFileName(((BasicFileChooserUI)this).getFileChooser().getName(f));
- }
-
- }
-
- static JComboBox access$directoryComboBox(MetalFileChooserUI var0) {
- return var0.directoryComboBox;
- }
- }
-